classSolution { public: vector<string> divideString(string s, int k, char fill){ vector<string> ans; string cur; int n = s.size(); for (int i = 0; i < n; i ++ ) { cur.push_back(s[i]); if (cur.size() == k) ans.push_back(cur), cur = ""; } while (cur.size() and cur.size() < k) cur.push_back(fill); if (cur.size() == k) ans.push_back(cur); return ans; } };
using LL = longlong; classSolution { public: longlongmaxRunTime(int n, vector<int>& nums){ int m = nums.size(); if (m < n) return0; sort(nums.begin(), nums.end()); LL sum = 0; for (auto& c : nums) sum += c; LL L = 0, R = sum; while (L < R) { LL mid = (L + R + 1) >> 1; LL cur = 0, cnt = 0; for (int i = 0; i < m; ) { if (nums[i] >= mid) { cnt ++ ; i ++ ; continue; } int j = i; while (j < m and cur < mid) { cur += nums[j]; j ++ ; } if (cur >= mid) { cnt ++ ; cur -= mid; } i = j; } if (cnt >= n) L = mid; else R = mid - 1; } return R; } };